package org.goldenport.g3.pipes

import java.net.URL
import java.io.File
import org.goldenport.wpath.WPathUtil.concat
import org.goldenport.g3._
import org.goldenport.g3.messages.{Get, Ping}
import org.goldenport.g3.messages.cli.CliCommand

/**
 * @since   Sep. 15, 2010
 * @version Oct. 10, 2010
 * @author  ASAMI, Tomoharu
 */
class G3Get(val uri: String, context: G3Context) extends G3Pipe(context) with ActivityActionable {
  def create_Activity(ctx: G3AgentContext): PartialFunction[AnyRef, AnyRef] = {
    case Nil => ctx.reconstitute(uri)
    case p: Ping => ctx.reconstitute(uri)
    case s: String => ctx.reconstitute(make_uri(s))
    case ss: Seq[String] => ss.map(s => ctx.reconstitute(make_uri(s)))
    case u: URL => ctx.reconstitute(u)
    case us: Seq[URL] => us.map(ctx.reconstitute)
    case f: File => ctx.reconstitute(f)
    case c: CliCommand => ctx.reconstitute(make_uri(c.uri))
  }

  private def make_uri(s: String): String = {
//    println("G3Get: " + s)
    concat(uri, s)
  }
}
